package com.cw.jeeyt.service.converter.git;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.git.GitProjectBo;
import com.cw.jeeyt.dao.model.git.GitProjectDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * git项目信息转换类
 *
 * @author chenw
 * @date 2019-04-08 21:44:19
 */
public class GitProjectConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static GitProjectBo do2Bo(GitProjectDo model) {
        GitProjectBo bo = new GitProjectBo();
        if (model == null) {
            return bo;
        }
        bo.setId(model.getId());
        bo.setProjectCode(model.getProjectCode());
        bo.setProjectName(model.getProjectName());
        bo.setLocalRepoPath(model.getLocalRepoPath());
        bo.setRemoteRepoUri(model.getRemoteRepoUri());
        bo.setGitUsername(model.getGitUsername());
        bo.setGitPassword(model.getGitPassword());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static GitProjectDo bo2Do(GitProjectBo bo) {
        GitProjectDo model = new GitProjectDo();
        if (bo == null) {
            return model;
        }
        model.setId(bo.getId());
        model.setProjectCode(bo.getProjectCode());
        model.setProjectName(bo.getProjectName());
        model.setLocalRepoPath(bo.getLocalRepoPath());
        model.setRemoteRepoUri(bo.getRemoteRepoUri());
        model.setGitUsername(bo.getGitUsername());
        model.setGitPassword(bo.getGitPassword());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<GitProjectBo> doList2BoList(List<GitProjectDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), GitProjectConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<GitProjectDo> boList2DoList(List<GitProjectBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), GitProjectConverter::bo2Do));
    }
}